package View.SetupScreens;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Model.Game;
import Model.Player;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import javax.swing.SwingConstants;

/**
 * Lets user(s) input names for their characters.
 * Sets name of computer players to "Computer 1", etc. as appropriate
 * If any name is null on click to continue, will stay on this card until user fixes.
 * Otherwise calls the next card.
 * @author Emily Curtin
 */
public class NameSetter extends JPanel {

	JLabel chooseName;
	public JButton setNames;
	public JLabel warning;
	
	JLabel player1Label;
	JLabel player2Label;
	JLabel player3Label;
	JLabel player4Label;
	
	public JTextField player1TB;
	public JTextField player2TB;
	public JTextField player3TB;
	public JTextField player4TB;
	
	
	/**
	 * Constructs the panel and all JComponents.
	 * JLabels are set to Player 1, Player 2, etc or Computer 1, Computer 2, etc.
	 * Textboxes for human players are editable, textboxes and names for Computer players are set.
	 * @param game - an instance of the main game. The parameter is "final" so that the inner actionlistener class can access it.
	 */
	public NameSetter(final Game game) {
		setBackground(Color.BLACK);
		setLayout(null);
		setPreferredSize(new Dimension(1200, 800));
		System.out.println("The number of players in game is " + game.getHumanPlayerCount());
		chooseName = new JLabel("CHOOSE YOUR NAME");
		chooseName.setHorizontalAlignment(SwingConstants.CENTER);
		chooseName.setFont(new Font("Helvetica", Font.BOLD, 65));
		chooseName.setForeground(new Color(204, 153, 0));
		chooseName.setSize(710, 80);
		chooseName.setLocation(245, 63);
		
		warning = new JLabel("ONE OR MORE PLAYERS DO NOT HAVE NAMES");
		warning.setFont(new Font("Helvetica", Font.BOLD, 44));
		warning.setForeground(new Color(153, 0, 0));
		warning.setSize(1033, 51);
		warning.setLocation(83, 595);
		warning.setVisible(false);
		
		setNames = new JButton("SET NAMES");
		setNames.setFont(new Font("Helvetica", Font.BOLD, 36));
		setNames.setForeground(new Color(204, 153, 0));
		setNames.setSize(295, 73);
		setNames.setLocation(20, 477);

		
		//Set the labels according to number of human players
		player1Label = new JLabel("PLAYER 1");
		player1Label.setFont(new Font("Helvetica", Font.BOLD, 36));
		player1Label.setForeground(new Color(204, 153, 0));
		player1Label.setSize(305, 50);
		player1Label.setLocation(280, 181);
		
		player1TB = new JTextField();
		player1TB.setFont(new Font("Helvetica", Font.PLAIN, 36));
		player1TB.setLocation(619, 181);
		player1TB.setForeground(new Color(204, 153, 0));
		player1TB.setSize(417, 50);
		player1TB.setEditable(true);
		
		player2Label = new JLabel("PLAYER 2");
		player2Label.setFont(new Font("Helvetica", Font.BOLD, 36));
		player2Label.setForeground(new Color(204, 153, 0));
		player2Label.setSize(305, 50);
		player2Label.setLocation(280, 298);
		
		player2TB = new JTextField();
		player2TB.setFont(new Font("Helvetica", Font.PLAIN, 36));
		player2TB.setLocation(619, 297);
		player2TB.setForeground(new Color(204, 153, 0));
		player2TB.setSize(417, 50);
		player2TB.setEditable(true);
		
		player3Label = new JLabel("PLAYER 3");
		player3Label.setFont(new Font("Helvetica", Font.BOLD, 36));
		player3Label.setForeground(new Color(204, 153, 0));
		player3Label.setSize(302, 50);
		player3Label.setLocation(283, 415);
		
		player3TB = new JTextField();
		player3TB.setFont(new Font("Helvetica", Font.PLAIN, 36));
		player3TB.setLocation(619, 413);
		player3TB.setForeground(new Color(204, 153, 0));
		player3TB.setSize(417, 50);
		player3TB.setEditable(true);
		
		player4Label = new JLabel("PLAYER 4");
		player4Label.setFont(new Font("Helvetica", Font.BOLD, 36));
		player4Label.setForeground(new Color(204, 153, 0));
		player4Label.setSize(305, 50);
		player4Label.setLocation(280, 532);
		
		player4TB = new JTextField();
		player4TB.setFont(new Font("Helvetica", Font.PLAIN, 36));
		player4TB.setLocation(619, 529);
		player4TB.setForeground(new Color(204, 153, 0));
		player4TB.setSize(417, 50);
		player4TB.setEditable(true);
		
		if ( game.getHumanPlayerCount() == 1){
			player2Label.setText("COMPUTER 1");
			player3Label.setText("COMPUTER 2");
			player4Label.setText("COMPUTER 3");
			
			player2TB.setText("COMPUTER 1");
			player2TB.setEditable(false);
			
			player3TB.setText("COMPUTER 2");
			player3TB.setEditable(false);
			
			player4TB.setText("COMPUTER 3");
			player4TB.setEditable(false);
		}
		else if ( game.getHumanPlayerCount() == 2){
			player3Label.setText("COMPUTER 1");
			player4Label.setText("COMPUTER 2");

			player3TB.setText("COMPUTER 1");
			player3TB.setEditable(false);
			
			player4TB.setText("COMPUTER 2");
			player4TB.setEditable(false);
		}
		else if ( game.getHumanPlayerCount() == 3){
			player4Label.setText("COMPUTER 1");
			
			player4TB.setText("COMPUTER 1");
			player4TB.setEditable(false);
		}
		
		add(chooseName);
		add(warning);
		add(setNames);
		
		add(player1Label);
		add(player2Label);
		add(player3Label);
		add(player4Label);
		
		add(player1TB);
		add(player2TB);
		add(player3TB);
		add(player4TB);	
	}

}
